package com.iyang.jpa.drools;

import org.drools.core.event.DebugAgendaEventListener;
import org.drools.core.event.DebugRuleRuntimeEventListener;
import org.kie.api.KieServices;
import org.kie.api.cdi.KContainer;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import java.util.ArrayList;

/**
 * @Author: Mu_YI
 * @Date: 2019/7/21 14:44
 * @Version 1.0
 */
public class HelloWorldDrools {

    public static void main(String[] args) {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kc = kieServices.getKieClasspathContainer();
        execute(kc);
    }

    /**
     * 执行器
     * @param kc
     */
    public static void execute(KieContainer kc){
        KieSession kieSession = kc.newKieSession("HelloWorldKS");
        kieSession.setGlobal("list",new ArrayList<Object>());
        kieSession.addEventListener(new DebugAgendaEventListener());
        kieSession.addEventListener(new DebugRuleRuntimeEventListener());
        final Message message = new Message();
        message.setMessage( "Hello World" );
        message.setStatus( Message.HELLO );
        kieSession.insert( message );
        kieSession.fireAllRules();
        kieSession.dispose();
    }

    /**
     * 类
     */
    public static class Message{
        public static final int HELLO   = 0;
        public static final int GOODBYE = 1;

        private String message;

        private Integer status;

        public static int getHELLO() {
            return HELLO;
        }

        public static int getGOODBYE() {
            return GOODBYE;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }
    }

}
